<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>GitHub Aouth 登录接入</title>
    <style>
        *{
            margin: 0px;
            padding: 0px;
        }
        html, body{
            height: 100%;
            height: 100%;
        }
        .container{
            width: 100%;
            height: 100%;
            background: #f1f1f1;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .login{
            width: 300px;
            height: 150px;
            background: #fff;
            border: 1px solid #eee;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .login a{
            color: #fff;
            background:#ff4700;
            display: block;
            width: 200px;
            height: 35px;
            text-align: center;
            text-decoration: none;
            font-size: 14px;
            line-height: 35px;
            border-radius: 3px;
        }
        .user>div{
            display: flex;
            width: 400px;
            height: 300px;
            background: #fff;
            flex-direction: column;
            justify-content: center;
            align-items: center;
        }
        .user img{
            width: 200px;
            height: 200px;
            border-radius: 3px;
        }
        .user-info{
            margin-top: 10px;
        }
    </style>
    <script src="./jquery.js"></script>
</head>
<body onload="getUserInfo()">
    <div class="container">
        <div class="login">
            <a href="#">点击此处进行gitHub登录</a>
        </div>
        <div class="user"></div>
    </div>
</body>
</html>
<script>
    function getUserInfo() {
        const code = window.location.search.split("?")[1].split('=')[1]
        const promise = new Promise((resolve, reject) => {
            $.ajax({
            url: `http://localhost:8080/login?code=${code}`,
            type: 'GET',
            success: (res) => {
                resolve(res)
            },
            error: (err) => {
                error(err)
            }
        })
    })
    promise.then((res) => {
        var html = `
        <div>
            <img src="${res.avatar_url}" alt=""/>
            <div class="user-info">
                <h3>${res.login}</h3>
            </div>
        </div>
        `
        $('.login').hide()
        $('.user').append(html)
    })
}
$(document).ready(function(){
    $('.login a').on('click', () =>{
        window.location.href = "https://github.com/login/oauth/authorize?client_id=your_client_id"
    })
})
</script>